/*
 * Created on Oct 13, 2005 7:34:54 AM
 * 
 * $Id: ss1.java,v 1.3 2005/10/16 14:15:07 olu Exp $
 *
 */
package tripleo.framework.svr.storage2;

import tripleo.fs.File;


public class ss2 implements IStorageServer2 {

	public ss2(String aString) {
		ass = new ss2_handler(aString);
		ch  = new LocalChannelImpl(ass);
	}
	
	/* (non-Javadoc)
	 * @see tripleo.framework.svr.storage.IStorageServer#createFile(java.lang.String, tripleo.framework.svr.storage.FileReader)
	 */
	public String createFile(String cap, File fr) {
		final CreateRequestImpl req = (CreateRequestImpl) ch.create(7);
		req.setReader(fr);
		req.setCap(cap);
		ch.send(req);
		ChannelResult res = ch.result();
		if (res.success())
			return ch.result().string;
		else
			throw new Error(res.failure);
	}
	
	/* (non-Javadoc)
	 * @see tripleo.framework.svr.storage.IStorageServer#deleteFile(java.lang.String)
	 */
	public void deleteFile(String cap) {
		final DeleteFileRequestImpl req = (DeleteFileRequestImpl) ch.create(9);
		ass.delete_file_req(req, ch);
		req.setCap(cap);
		ch.send(req);
		ChannelResult res = ch.result();
		if (!res.success())
			throw new Error(res.failure);
	}

	/* (non-Javadoc)
	 * @see tripleo.framework.svr.storage.IStorageServer#readFile(java.lang.String, long)
	 */
	public File readFile(String cap, long startIndex) {
		final ReadFileRequestImpl req = (ReadFileRequestImpl) ch.create(8);
		ass.read_file_req(req, ch);
		req.setCap(cap);
		req.setStartIndex(startIndex);
		ch.send(req);
		ChannelResult res = ch.result();
		if (res.success())
			return ch.result().stream;
		else
			throw new Error(res.failure);
	}

	private ss2_handler ass;
	private Channel     ch;

}
